<?php 
if(!defined('BASEPATH'))
		exit('No direct script access allowed');
	class Message_Type extends CI_Controller {
		function __construct(){
			session_start();
			parent::__construct();
		}
		
		function index($query_id=0, $order_by='created_date', $sort_order='asc', $current_page=0){
			$search_by='';
			$search_by_value='';
				if($query_id == '0'){		
					//echo '<pre>';print_r($_SESSION);exit;
					unset($_SESSION['search']);
				}else{
					if(isset($_SESSION['search'])){
					$array = $_SESSION['search'];
					//echo '<pre>';print_r($_SESSION);exit;
					$search_by = $array['search_by'];
					$search_by_value = $array['search'];
					//echo '<pre>';print_r($search_by_value);exit;
					}
				}
			$results_per_page = 3;
		
		
			$data = array('www-command'=>'messagetypes-all_messagetypes', 'current_page'=>$current_page, 'results_per_page'=>$results_per_page, 'order_by'=>$order_by, 'sort_order'=>$sort_order, 'search_by'=>$search_by, 'search_by_value'=>$search_by_value);
			//echo '<pre>';print_r($data);exit;
			$response = $this->get_message_type_list($data);
		//echo '<pre>';print_r($response);exit;
		if($response->message !== 'No Review'){
			$this->load->library('pagination');			
			$config['base_url'] = base_url().'admin/message_type/index/'.$query_id.'/'.$order_by.'/'.$sort_order;
			$config['per_page'] = $results_per_page;
			$config['total_rows']  = $response->total;
			$config['uri_segment'] = 7;
			$config['num_links'] = 1;
			$config['prev_link'] = 'Previous';
			$config['next_link'] = 'Next';
			$config['first_link'] = 'First';
			$config['last_link'] = 'Last';
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			$data['registerusers'] = $response;
			$data['error'] = '';
			}else{
				$data['error'] = 1;
				$data['all_registerusers'] = '';
			}
			//echo '<pre>';print_r($data);exit;
			$data['sort_order'] = $sort_order;
			$data['order_by'] = $order_by;
			$data['query_id'] = $query_id;
			$data['search_by'] = $search_by;
			$data['search_by_value'] = $search_by_value;
			$data['user_fields'] = array('user_name'=>'Name', 'email'=>'Email', 'city'=>'City', 'status'=>'Status', 'created_date'=>'Date');
			$this->load->view('admin/message_type', $data);
 		}

		function get_message_type_list($data){
				$url = CURL_URL;
				$string = http_build_query($data);
				//echo '<pre>';print_r($data);exit;
				$ch = curl_init($url);
				curl_setopt($ch,CURLOPT_POST,true);
				curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
				curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
				$response = json_decode(curl_exec($ch));
				//echo '<pre>';print_r($response);exit;
				curl_close($ch);
				return $response;
			}
}